package cn.funeralobjects.youtube.dl.extension.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * @author FuneralObjects
 * Create date: 2020/4/13 1:51 AM
 */
public enum TaskStatusType {
    /**
     * 等待中
     */
    WAITING(1),
    /**
     * 执行中
     */
    RUNNING(2),
    /**
     * 已完成
     */
    COMPLETED(3),
    /**
     * 被中断
     */
    INTERRUPTED(4);

    @Getter
    @JsonValue
    public Integer num;

    TaskStatusType(Integer num) {
        this.num = num;
    }

    @JsonCreator
    public static TaskStatusType createByNum(Integer num) {
        if (num == null) {
            return null;
        }
        for (TaskStatusType status : TaskStatusType.values()) {
            if (status.getNum().equals(num)) {
                return status;
            }
        }
        return null;
    }
}
